package com.sychip.fhc.app.wsn.common.util

import androidx.compose.ui.graphics.Color


val  RssiColors  = listOf(Color(0xFF409EFF), Color(0xFF13CE66), Color(0xFFFFBA00), Color(0xFFFB0D0D)  )


/**
 * Rssi color
 *
 * @return
 */
fun Int.rssiColor(): Color {
    return when {
        this > -50 -> RssiColors[0]
        this > -80 -> RssiColors[1]
        this > -90 -> RssiColors[2]
        else -> RssiColors[3]
    }
}
fun Double.round(decimal:Int = 0): String {
    return String.format("%.${decimal}f", this)
}


fun String.rssiColor(invalidColor: Color): Color {

   if(this.toIntOrNull() != null) return when {
        this.toInt() > -50 -> RssiColors[0]
        this.toInt() > -80 -> RssiColors[1]
        this.toInt() > -90 -> RssiColors[2]
        else -> RssiColors[3]
    }
    else return invalidColor
}

fun String.perColor(invalidColor: Color): Color {

    if(this.toIntOrNull() != null) return when {
        this.toInt() > -50 -> RssiColors[0]
        this.toInt() > -80 -> RssiColors[1]
        this.toInt() > -90 -> RssiColors[2]
        else -> RssiColors[3]
    }
    else return invalidColor
}